import { createContext, ReactNode, useContext, useState } from 'react';

export interface PointSharedState {
  sharedPoint: number[] | null;
  setSharedPoint: (point: number[] | null) => void;
}

const PointContext = createContext<PointSharedState>({
  sharedPoint: null,
  setSharedPoint: () => {},
});

export const PointProvider = ({ children }: { children: ReactNode }) => {
  const [sharedPoint, setSharedPoint] = useState<number[] | null>(null);

  return (
    <PointContext.Provider
      value={{
        sharedPoint,
        setSharedPoint,
      }}
    >
      {children}
    </PointContext.Provider>
  );
};

export const usePointContext = () => useContext(PointContext);
